import { Request, Response } from 'express';
import mockjs from 'mockjs';

const waitTime = (time: number = 100) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};

export default {
  'GET /user/list':async (req: Request, res: Response) => {
    await waitTime(500)
    res.send({
      code: 0,
      data: mockjs.mock({
        'list|16': [{ "key|+1": 1, createTime: '@datetime', name:'@last', 'age|20-50': 50, 'sex|0-2': 2 }],
      })
    });
  },
  'GET /recyclable/list':async (req: Request, res: Response) => {
    await waitTime(500)
    res.send({
      code: 0,
      data: mockjs.mock({
        'list|8': [{ id: '@id', createTime: '@datetime', 'name|1': ['瓶子', '纸壳子'] }],
      })
    })
  },
  'POST /recyclable/edit':async (req: Request, res: Response) => {
    await waitTime(1000)
    res.send({
      code: 0,
      data: req.body
    })
  }
}